package org.feng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.feng.entity.RolePermission;
import org.feng.mapper.RolePermissionMapper;
import org.feng.service.IPermissionService;
import org.feng.service.IRolePermissionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 * 角色权限关系表 服务实现类
 * </p>
 *
 * @author fengjinsong
 * @since 2023-09-02
 */
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements IRolePermissionService {

    @Resource
    private IPermissionService permissionService;

    @Override
    public Set<String> listPermissionCodeByRole(Set<Integer> roleIdSet) {
        LambdaQueryWrapper<RolePermission> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.in(RolePermission::getRoleId, roleIdSet);

        Set<Integer> permissionIdSet = this.list(queryWrapper).stream().map(RolePermission::getPermissionId).collect(Collectors.toSet());
        return permissionService.listPermissionCodeByIds(permissionIdSet);
    }
}
